package Other.DP;

/**
 * @author:gao
 * @date:2020/7/14
 * @time:19:12
 * @version:0.0.1
 * @description:none
 */


//714. 买卖股票的最佳时机含手续费
public class MaxProfitWithFee {
}

class Solution {
    public int maxProfit(int[] prices, int fee) {
        if(prices==null||prices.length==0) return 0;
        int hasNo = 0;
        int has = -prices[0];
        for (int i = 1; i <prices.length ; i++) {
            int tmpNo = hasNo;
            hasNo = Math.max(hasNo,has+prices[i]-fee);
            has = Math.max(has,tmpNo-prices[i]);
        }
        return hasNo;
    }
}